<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

use think\Config;
use think\Session;
use fast\Http;



class Taos extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();

    }

    //http://fastaws.test/api/taos/phpinfo
    public function phpinfo()
    {
        
        phpinfo();
    }

    //http://fastaws.test/api/taos/login
    public function login()
    {
        $url = "http://127.0.0.1:6041/rest/login/root/taosdata";
        $ret = Http::get($url);
        echo $ret."<br>login";
    }

    //http://fastaws.test/api/taos/dosql?sql=select * from power.d1001
    //curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from power.d1001' 220.132.102.45:6041/rest/sql
    //insert into power.d1001 values (now, 13.1, 35);
    public function dosql()
    {
        $sq = $this->request->request('sql', "");

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://220.132.102.45:6041/rest/sql');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $sq);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
//            'Content-Type: application/json',
            'Authorization: Basic cm9vdDp0YW9zZGF0YQ=='
        ]);
        $ret = curl_exec($ch);

        echo $ret." <br><br>dosql -- ok";
    }

    //http://fastaws.test/api/taos/test
    public function test()
    {

        $this->success('返回成功');
    }


}





